package com.example.drainage.ui.calendar

import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.example.arm.base.BaseActivity
import com.example.drainage.R
import com.example.drainage.databinding.ActivityCalendarBinding
import timber.log.Timber
import java.util.*

/**
 * @author 创建人 ：yanghaozhang
 * @version 1.0
 * @package 包名 ：com.example.drainage.ui.calendar
 * @createTime 创建时间 ：2021/11/25
 * @modifyBy 修改人 ：
 * @modifyTime 修改时间 ：
 * @modifyMemo 修改备注：
 */
class CalendarActivity : BaseActivity<ActivityCalendarBinding>() {

    private val calendarAdapter = CalendarAdapter()

    override fun initView(savedInstanceState: Bundle?): ActivityCalendarBinding =
        ActivityCalendarBinding.inflate(layoutInflater)

    override fun initData(savedInstanceState: Bundle?) {
        binding.recyclerView.apply {
            adapter = calendarAdapter
            addItemDecoration(
                FloatDecoration(
                    this@CalendarActivity,
                    binding.recyclerView,
                    R.layout.layout_calendar_header,
                    object : FloatDecoration.DecorationCallback {
                        override fun getDecorationFlag(position: Int): String {
                            //区分不同条目装饰 View 的 Flag
                            return position.toString()
                        }

                        override fun onBindView(decorationView: View, position: Int) {
                            Timber.d("$position----")
                            decorationView.findViewById<TextView>(R.id.tv_header).text =
                                SchedulingCalendarUtil.getTimeStrFromMonthIndex(position)
                        }
                    })
            )

            scrollToPosition(SchedulingCalendarUtil.getNowMonthIndex())
        }

    }
}